package com.group.eams.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.group.eams.pojo.dto.*;
import com.group.eams.pojo.entity.AssetAllocate;
import com.group.eams.pojo.vo.AllocateFixedDetailListVo;
import com.group.eams.pojo.vo.AllocateFixedListVo;
import com.group.eams.pojo.vo.AssetAllocateListVo;
import com.group.eams.service.AssetAllocateService;
import com.group.result.Result;
import com.group.result.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 资产调拨表(AssetAllocate)表控制层
 *
 * @author 
 * @since 2024-10-30 12:58:28
 */
@RestController
@RequestMapping("/assetAllocate")
public class AssetAllocateController  {
    /**
     * 服务对象
     */
    @Autowired
    private AssetAllocateService assetAllocateService;

    /**
     * 资产调拨信息列表
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public Result<List<AssetAllocateListVo>> findAssetAllocateByWhere(AssetAllocateQueryDto AssetAllocateQueryDto) {
        Page<AssetAllocateListVo> disposeListVoPage = assetAllocateService.findAssetAllocateByWhere(AssetAllocateQueryDto);
        return Result.buildSuccess(disposeListVoPage.getTotal(),disposeListVoPage.getRecords());
    }

    /**
     * 按id查询资产调拨信息
     */
    @RequestMapping(value = "/find", method = RequestMethod.GET)
    public Result<AssetAllocate> find(@RequestParam Long id) {
        AssetAllocate AssetAllocate = assetAllocateService.getById(id);
        return Result.buildSuccess(AssetAllocate);
    }

    /**
     * 查询所有资产调拨信息
     */
    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    public Result<List<AssetAllocate>> findAll(){
        List<AssetAllocate> AssetAllocateList = assetAllocateService.list();
        return Result.buildSuccess(AssetAllocateList);
    }

    /**
     * 添加资产调拨信息
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Result<Object> add(@RequestBody AssetAllocate AssetAllocate) {
        boolean result = assetAllocateService.save(AssetAllocate);
        return result ? Result.buildSuccess() : Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 修改资产调拨信息
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Result<Object> update(@RequestBody AssetAllocate assetAllocate){
        boolean result = assetAllocateService.updateById(assetAllocate);
        return result ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量添加资产调拨信息
     */
    @RequestMapping(value = "/batchAdd",method = RequestMethod.POST)
    public Result<Object> batchAdd(@RequestBody List<AssetAllocate> assetAllocates){
        boolean result = assetAllocateService.saveBatch(assetAllocates);
        return result ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量修改资产调拨信息
     */
    @RequestMapping(value = "/batchUpdate",method = RequestMethod.POST)
    public Result<Object> batchUpdate(@RequestBody List<AssetAllocate> assetAllocates){
        boolean result = assetAllocateService.updateBatchById(assetAllocates);
        return result ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量移除资产调拨信息
     */
    @RequestMapping(value = "/batchRemove",method = RequestMethod.POST)
    public Result<Object> batchRemove(@RequestBody List<Long> ids){
        boolean result = assetAllocateService.removeByIds(ids);
        return result ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 查询所有固有资产信息
     */
    @RequestMapping(value = "/findAllocateFixed",method = RequestMethod.GET)
    public Result<List<AllocateFixedListVo>> findAllocateFixed(FixedAssetQueryDto fixedAssetQueryDto) {
        Page<AllocateFixedListVo> allocateFixedByWhere = assetAllocateService.findAllocateFixedByWhere(fixedAssetQueryDto);
        return Result.buildSuccess(allocateFixedByWhere.getTotal(),allocateFixedByWhere.getRecords());
    }

    /**
     * 根据选择的id查询资产
     */
    @RequestMapping(value = "/addAllocateFixedDetail",method = RequestMethod.POST)
    public Result<List<AllocateFixedDetailListVo>> addAllocateFixedDetail(@RequestBody AssetPartDto assetPartDto) {
        Page<AllocateFixedDetailListVo> allocateFixedDetailListVoPage = assetAllocateService.addAllocateFixedDetail(assetPartDto);
        return Result.buildSuccess(allocateFixedDetailListVoPage.getTotal(),allocateFixedDetailListVoPage.getRecords());
    }

    /**
     * 按申请单号查询详细固有资产信息
     */
    @RequestMapping(value = "/findAllocateFixedDetail",method = RequestMethod.GET)
    public Result<List<AllocateFixedDetailListVo>> findAllocateFixedDetail(ApplyNumFixedAssetQueryDto applyNumFixedAssetQueryDto) {
        Page<AllocateFixedDetailListVo> allocateFixedDetailListVoPage = assetAllocateService.findAllocateFixedDetail(applyNumFixedAssetQueryDto);
        return Result.buildSuccess(allocateFixedDetailListVoPage.getTotal(),allocateFixedDetailListVoPage.getRecords());
    }

    /**
     * 根据申请单号和assetId删除
     */
    @RequestMapping(value = "/deleteByAssetIds", method = RequestMethod.POST)
    public Result<Object> batchDeleteByAssetIds(@RequestBody BatchDeleteIdsDto batchDeleteIdsDto){
        int result = assetAllocateService.deleteByApplicationNum(batchDeleteIdsDto);
        return result > 0 ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 根据申请单号和assetId修改
     */
    @RequestMapping(value = "/updateByAssetIds", method = RequestMethod.POST)
    public Result<Object> batchDeleteByAssetIds(@RequestBody BatchUpdateIdsDto<AssetAllocate> batchUpdateIdsDto){
        int result = assetAllocateService.updateByApplicationNum(batchUpdateIdsDto);
        return result > 0 ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 根据申请单号查询
     */
    @RequestMapping(value = "/findByNum",method = RequestMethod.GET)
    public Result<AssetAllocate> findByNum(@RequestParam String applicationNum) {
        AssetAllocate assetAllocate = assetAllocateService.findAllocateByNum(applicationNum);
        return Result.buildSuccess(assetAllocate);
    }
}

